/**
 * Created by Brant on 2016/12/28.
 */
module.exports = function ($scope, $state, newsService) {
  $rootScope.showCaseDiv = false;
    var sendUserId = "20";
    var receiveUserId = "2";
    var itemId = "1";
    $scope.init = function () {
        $("#yb-message-list1").click(function () {
            $("#yb-list1").show();
            $("#yb-list2").hide();
            var target = $("#yb-message-list1");
            var which = parseInt(target.val());
            target.addClass("active");
            target.siblings().removeClass("active");
            $('[id*="tab-"]').addClass('hide');
            $('#tab-' + which).removeClass('hide');
        });
        $("#yb-message-list2").click(function () {
            $("#yb-list1").hide();
            $("#yb-list2").show();
            var target = $("#yb-message-list2");
            var which = parseInt(target.val());
            target.addClass("active");
            target.siblings().removeClass("active");
            $('[id*="tab-"]').addClass('hide');
            $('#tab-' + which).removeClass('hide');
        });

        // 查询动态消息
        newsService.queryMessage(sendUserId, "", "", "1", "10").then(function (data) {
            var modelArr = data.data;
            $scope.records = data.data;
            $scope.dddd(data.data);
            $scope.setpaging(data);

        }, function (response) {
            console.error('selectmessage error', response.status, response.statusText);
        });
    };


    $scope.dddd = function (ss) {
        setTimeout(function () {

            for (var i = 0; i < ss.length; i++) {
                if (ss[i].status == 3) {
                    $('.sdf' + ss[i].id).hide();
                    //noinspection JSAnnotator
                    $('#' + ss[i].id).html("已经接受");
                    $('#' + ss[i].id).css('background', '#43CD80');
                    $('#' + ss[i].id).show();

                } else if (ss[i].status == 5) {
                    $('.sdf' + ss[i].id).hide();
                    //noinspection JSAnnotator
                    $('#' + ss[i].id).html("已经拒绝");
                    $('#' + ss[i].id).css('background', '#FF0000');
                    $('#' + ss[i].id).show();
                }
            }
        }, 50);

    };
    //请求完成后设置分页
    $scope.setpaging = function (data) {
        $('.select').css('color', '#666');
        // $scope.newXin_1Date = data.data;
        $scope.totalPage = data.totalPage;
        $scope.totalCount = data.totalCount;
        $scope.totalPas = data.totalPas;
        $scope.page = data.currentPage;
        setTimeout(function () {
            $('.select' + $scope.page).css('color', 'red');
        }, 50);
    }

    /*用户点击分页点击改变页码*/
    $scope.changePage = function (currentPage) {
        if (currentPage <= $scope.totalPage && currentPage > 0) {
            // totalPage 页码
        } else {
            console.log('列表页码越界!');
        }
    }


    // 接受
    $scope.show = false;
    $scope.acceptMsg = function (sendUserId, id) {
        newsService.acceptOrRejectMsg(3, id).then(function (data) {
            setTimeout(function () {
                $('.sdf' + id).hide();
                //noinspection JSAnnotator
                $('#' + id).html("已经接受");
                $('#' + id).show();
            }, 50);
        }, function (response) {
            console.error('updatemessage error', response.status, response.statusText);
        });
    };

    // 拒绝
    $scope.rejectMsg = function (sendUserId, id) {

        newsService.RefuseMsg(5, id, itemId).then(function (data) {

            setTimeout(function () {
                $('.sdf' + id).hide();
                //noinspection JSAnnotator
                $('#' + id).html("已经拒绝");
                $('#' + id).show();
            }, 50);

        }, function (response) {
            console.error('updatemessage error', response.status, response.statusText);
        });
    };
    // 系统消息
    $scope.SystemMsg = function () {
        newsService.SystemMsg("37","0","10").then(function (data) {
            $scope.system = data.data;


        }, function (response) {
            console.error('updatemessage error', response.status, response.statusText);
        });
    };


    $scope.init();




};
